package com.search;

import com.alibaba.fastjson2.JSONObject;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Properties;

public class StringTool {

    static String jsonString = "{\n" +
            "\t\"Host\": \"obs.jiatu.cloud\",\n" +
            "\t\"Connection\": \"keep-alive\",\n" +
            "\t\"Content-Length\": \"190\",\n" +
            "\t\"clientinfo\": \"{\\\"appid\\\":\\\"wx04b02a49ed8f0be3\\\",\\\"channel\\\":\\\"obs-wx-mini\\\",\\\"libcode\\\":\\\"STL50\\\",\\\"libType\\\":1}\",\n" +
            "\t\"xweb_xhr\": \"1\",\n" +
            "\t\"jwt\": \"eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.jUthzDel7llQbaByNeICu69iCQVX0Zzgj6yZxin1VOuBAOwSHTzg9w1vx70mZq5JDFdaaScU93kWIbR4i7wZddhLJCulqs2roaPdlaNNXdFgSwQZmsClAq7UR2YY3jbYdoBzj7h7CONXFf4Vu5oogdoifZSbxS6XTreR5X19sfo.O8LDC_tj_j9TOHxU.vJIDSl3VfUxA8TBpEpJBahXIOWw41Cf_ITTLwhsTy4TFg3BmTtl-Rrk5E2qKuE9c9D8BB2SAWCRuKpjSkrfVc6sHDIgJNxbyOtRzhqV9W4N4oIbeXS9FYMr6HRL-KjPW5c_CrtsZ51y9-v03C12TWwVEFIi0EwuNzLSYqfBit1YBY8BGYBSrI0SoraLqeQBBtUXKzLkuLpe-bzevKMMzku-zkprZxJOCDWNeCJvvZRH61EsjHYiCk-IhGB1M2V2ahNh3itfoC2H7SMJLp1B1kzeijHcpR5xQJ03PnB4Z98dfxz7wDbsHbSYS04jZ_G9g-OM3taSb7JYnoggHu8XlaXo37XRLLDP8r_89LTEtEHpTZLJeDVg1RGprh5Th71_kEY6tD8JwrNKw2HJ_IpW5irOsi5KACx3bJmQo-5RoJZNrbJi03pljhJcEap9fKuyjE_p6TsViCYPrWiqmKF-GaHqfeM7MKZ9b4euujO65mHRCwV7VT1PEF0vN.hknjlnUkQldlArnpCU7veQ\",\n" +
            "\t\"X-Okapi-Tenant\": \"\",\n" +
            "\t\"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090b19)XWEB/9193\",\n" +
            "\t\"obsBindId\": \"\",\n" +
            "\t\"Content-Type\": \"application/json\",\n" +
            "\t\"Accept\": \"*/*\",\n" +
            "\t\"Sec-Fetch-Site\": \"cross-site\",\n" +
            "\t\"Sec-Fetch-Mode\": \"cors\",\n" +
            "\t\"Sec-Fetch-Dest\": \"empty\",\n" +
            "\t\"Referer\": \"https://servicewechat.com/wx04b02a49ed8f0be3/22/page-frame.html\",\n" +
            "\t\"Accept-Encoding\": \"gzip, deflate, br\",\n" +
            "\t\"Accept-Language\": \"zh-CN,zh;q=0.9\"\n" +
            "}";

    private  static  String entity = "{\"keyword\":\"9787544783064\",\"pageNo\":1,\"pageSize\":12,\"publisher\":\"\",\"author\":\"\",\"subject\":\"\",\"classno\":\"\",\"days\":\"\",\"language\":\"\",\"pubdate\":\"\",\"holdingStatus\":0,\"matchType\":0,\"subLibcode\":\"\"}";

    String[] dfgfd = {"gg","hgh"};

    static String pre = "post";

    public static void main(String[] args) throws IOException {

        //readProToHeader();
        /*LinkedHashMap map = new LinkedHashMap();
        map.put("aaa","jjj");
        map.put("bbb","hhh");
        System.out.println(map);*/
        Properties properties = new Properties();
        InputStream inputStream = StringTool.class.getClassLoader().getResourceAsStream("data.properties");
        properties.load(inputStream);
        for(Object key:properties.keySet()){
            //System.out.println("post.setHeader(\""+key+"\",\""+properties.get(key)+"\");");
            System.out.println("connection.header(\""+key+"\",\""+properties.get(key)+"\");");
        }

    }

    @Test
    public static void readProToHeader() throws IOException {
        Properties properties = new Properties();
        InputStream inputStream = StringTool.class.getClassLoader().getResourceAsStream("data.properties");
        properties.load(inputStream);
        for(Object key:properties.keySet()){
            //System.out.println("post.setHeader(\""+key+"\",\""+properties.get(key)+"\");");
            System.out.println("connection.header(\""+key+"\",\""+properties.get(key)+"\");");
        }
    }

    public static void entityPut(){
        JSONObject res =  JSONObject.parseObject(entity);
        //System.out.println(res);
        for(String key:res.keySet()){
            System.out.println("entity.put(\""+key+"\",\""+res.get(key)+"\");");
        }
    }

    public static void setHeader(){
        JSONObject res =  JSONObject.parseObject(jsonString);
        //System.out.println(res);
        for(String key:res.keySet()){
            System.out.println(pre+".setHeader(\""+key+"\",\""+res.get(key)+"\");");
        }
    }
}
